home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / statbox.exe / TSTATBOX.PAS < prev   
Pascal/Delphi Source File  |  1993-03-21  |  10KB  |  280 lines

  1. Program TStatBox;
  2.  
  3. {==============================================================}
  4. {Demos the usage of the Unit STATBOX.TPU, a dynamically sized, }
  5. {status dialog.  See the notes within this code for usage of   }
  6. {the 2 methods in the Unit.                                    }
  7. {Special thanks again to Steve Schafer for the initial code    }
  8. {and idea.                                                     }
  9. {The following files were all originally distributed together: }
  10. {STATBOX.PAS (*Unit Code*)                                     }
  11. {STATBOX.TPU (*Compiled Unit, TP6.0*)                          }
  12. {TSTATBOX.PAS (*This Demo Code*)                               }
  13. {TSTATBOX.EXE (*Compiled Demo Code, TP6.0*)                    }
  14. {                                                              }
  15. {If you have any suggestions or improvements, please let me    }
  16. {know, my Compuserve ID is 72400,2215.                         }
  17. {This code has been very useful to me, and any improvements    }
  18. {would only make my job easier!                                }
  19. {==============================================================}
  20.  
  21. Uses
  22.     Objects,Views,Crt,App,Drivers,Menus,Gadgets,STATBOX;
  23.  
  24. Type
  25.     TStatTest = object(TApplication)
  26.           Heap : PHeapView;
  27.           Constructor Init;
  28.           Procedure InitMenuBar; virtual;
  29.           Procedure InitStatusLine; virtual;
  30.           Procedure Idle; virtual;
  31.           Procedure HandleEvent(var Event:TEvent); virtual;
  32.           Procedure ShowDialog1;
  33.           Procedure ShowDialog2;
  34.           Procedure ShowDialog3;
  35.     End;  {Object Declaration}
  36.  
  37.  
  38. Const
  39.      cmDialog1 = 100;
  40.      cmDialog2 = 101;
  41.      cmDialog3 = 102;
  42.  
  43. {*************************************************************************}
  44.  
  45. Constructor TStatTest.Init;
  46. Var
  47.    R : TRect;
  48. Begin
  49.      TApplication.Init;
  50.  
  51.      {Put heap memory report in our status line}
  52.      {To verify disposal of all heap allocation}
  53.      {upon closure of the TStatusDialog.       }
  54.      {A nice on-the-fly debugging tool!        }
  55.      GetExtent(R);
  56.      R.A.X := R.B.X - 9;
  57.      R.A.Y := R.B.Y - 1;
  58.      Heap  := New(PHeapView, Init(R));
  59.      Insert(Heap);
  60. End;
  61.  
  62. {*************************************************************************}
  63.  
  64. Procedure TStatTest.InitMenuBar;
  65. Var
  66.    R : TRect;
  67. Begin
  68.      GetExtent(R);
  69.      R.B.Y := R.A.Y +1;
  70.      MenuBar:= New(PMenuBar, Init(R, NewMenu(
  71.                NewSubMenu('~R~un Demos',hcNoContext, NewMenu(
  72.                NewItem('Run Demo1', 'F1', kbF1, cmDialog1, hcNoContext,
  73.                NewItem('Run Demo2', 'F2', kbF2, cmDialog2, hcNoContext,
  74.                NewItem('Run Demo3', 'F3', kbF3, cmDialog3, hcNocontext,
  75.                NIL)))),
  76.                NIL))));
  77. End;
  78.  
  79. {*************************************************************************}
  80.  
  81. Procedure TStatTest.InitStatusLine;
  82. Var
  83.    R : TRect;
  84. Begin
  85.      GetExtent(R);
  86.      R.A.Y := R.B.Y-1;
  87.      StatusLine := New(PStatusLine, Init(R,
  88.                    NewStatusDef(0, $FFFF,
  89.                    NewStatusKey('~F10~ Menu', kbF10, cmMenu,
  90.                    NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  91.                    NIL)),
  92.                    NIL)));
  93. End;
  94.  
  95. {*************************************************************************}
  96.  
  97. Procedure TStatTest.Idle;
  98. Begin
  99.      TApplication.Idle;
  100.      Heap^.Update;
  101. End;
  102.  
  103. {*************************************************************************}
  104.  
  105. Procedure TStatTest.HandleEvent(var Event: TEvent);
  106. Begin {HandleEvent}
  107.       TApplication.HandleEvent(Event);
  108.  
  109.       Case Event.What of
  110.            evCommand : Begin
  111.                             Case Event.Command of
  112.                                  cmDialog1 : ShowDialog1;
  113.                                  cmDialog2 : ShowDialog2;
  114.                                  cmDialog3 : ShowDialog3;
  115.                             Else
  116.                                 Exit;
  117.                             End;  {Case Event.Command of}
  118.                             ClearEvent(Event);
  119.                        End; {evCommand}
  120.       End;
  121. End; {HandleEvent}
  122.  
  123. {*************************************************************************}
  124.  
  125. Procedure TStatTest.ShowDialog1;
  126.  
  127. {Demonstrates one of the simplest types of TStatusDialog}
  128. {Does not allow you to break into the processing,       }
  129. {therefore, we don't need a Cancel Message. Note that   }
  130. {the length of the Proc1 Message and the Done1 Message  }
  131. {should be roughly the same, this assures them both     }
  132. {being centered in the display when they are called     }
  133. {upon.  If you don't do this, they they will end        }
  134. {up being left justified within their bounds, not bad,  }
  135. {but not the professional look we want in our app's.    }
  136.  
  137. Var
  138.    D : PStatusDialog;
  139.    C : Integer;
  140.    E : TEvent;
  141. Begin
  142.      D := New(PStatusDialog, Init('[ STATUS BOX DEMO 1 ]',
  143.                                   'Processing Record',
  144.                                   'Cycle In Process...',
  145.                                   '  Cycle Finished!  ',
  146.                                   '',
  147.                                   'Hit Any Key To Continue!'));
  148.      DeskTop^.Insert(D);
  149.  
  150.  
  151.      {Your Processing code would go here, in the For-Do loop or }
  152.      {something similar.  For a repetitious task that you want  }
  153.      {to be sure the user knows something is going on, do a     }
  154.      {little, or one step, then report on the status.  A good   }
  155.      {example is reading or writing records.  Keep the dialog   }
  156.      {open until a key is pressed, or could be a mouse click,   }
  157.      {so the user can get the Help message you wished to give   }
  158.      {them upon the completion of the "processing"              }
  159.  
  160.      For C := 1 to 200 Do
  161.      Begin
  162.           D^.Update(cmValid, C);
  163.           Delay(50);
  164.           GetEvent(E);     {eat any misc key hits during processing}
  165.      End;
  166.      D^.Update(cmOk, C);
  167.      Repeat
  168.      Until KeyPressed;
  169.      DeskTop^.Delete(D);
  170.      Dispose(D, Done);
  171. End;
  172.  
  173. {*************************************************************************}
  174.  
  175. Procedure TStatTest.ShowDialog2;
  176.  
  177. {Demonstrates a TStatusDialog which includes a cancel message}
  178. {Note that you have to include code to cancel out, it won't  }
  179. {just happen automatically!  Also note the GetEvent(E) lines,}
  180. {this is to trap random key hits, which will trigger the     }
  181. {close of the dialog if they aren't intercepted.             }
  182. {Note if you have a Cancel message, it needs to be the same  }
  183. {length as the Main1 and Proc1 messages to be properly       }
  184. {centered in the dialog.                                     }
  185.  
  186. Var
  187.    D : PStatusDialog;
  188.    C : Integer;
  189.    E : TEvent;
  190. Begin
  191.      D := New(PStatusDialog, Init('[ STATUS BOX DEMO 2 ]',
  192.           {Main1 Message==>}     'Processing Record',
  193.           {Proc1 Message==>}     'Hit CTRL-BREAK to Interrupt Processing',
  194.           {Done1 Message==>}     '   You Didn''t Interrupt Processing   ',
  195.           {Cancel Message==>}    '     You Interrupted Processing...    ',
  196.           {Help  Message==>}     'Hit Any Key To Continue'));
  197.  
  198.      DeskTop^.Insert(D);
  199.      For C := 1 to 200 Do
  200.      Begin
  201.           D^.Update(cmValid, C);
  202.           If CtrlBreakHit Then
  203.           Begin
  204.                CtrlBreakHit := FALSE;
  205.                GetEvent(E);             {eat the CTRL-BREAK}
  206.                D^.Update(cmCancel, C);
  207.                C := 200;
  208.                Repeat
  209.                Until KeyPressed;
  210.                DeskTop^.Delete(D);
  211.                Dispose(D, Done);
  212.                Exit; {Leave this procedure}
  213.           End;
  214.           Delay(50);
  215.           GetEvent(E);     {eat any misc. key hits during processing}
  216.      End;
  217.      D^.Update(cmOk, C);
  218.      Repeat
  219.      Until KeyPressed;
  220.      DeskTop^.Delete(D);
  221.      Dispose(D, Done);
  222. End;
  223.  
  224. {*************************************************************************}
  225.  
  226. Procedure TStatTest.ShowDialog3;
  227.  
  228. {Demonstrates the dynamic sizing of the TStatusDialog, it is }
  229. {sized to the length needed to accomodate our long Help      }
  230. {message.